package cn.itcast.service.impl;

import cn.itcast.entity.PageResult;
import cn.itcast.entity.QueryPageBean;
import cn.itcast.mapper.CheckItemMapper;
import cn.itcast.pojo.CheckItem;
import cn.itcast.service.CheckItemService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service(interfaceClass = CheckItemService.class)
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    CheckItemMapper mapper;


    @Transactional
    public void add(CheckItem checkItem) {

       mapper.add(checkItem);
    }



    public PageResult queryPage(QueryPageBean pageBean) {

        //pageHelper.starpage(当前页码，每页展示条数)
        PageHelper.startPage(pageBean.getCurrentPage(),pageBean.getPageSize());

        //将查寻出的结果封装为集合对象
        List<CheckItem> list = mapper.selectByCondition(pageBean.getQueryString());

        //将集合载入到pageInfo中，反推出总页数
        PageInfo pi = new PageInfo(list);

        //将总页数与当前页集合载入到PageResult进行返回
        PageResult result = new PageResult(pi.getTotal(),list);

        return result;
    }



    @Override
    public CheckItem findById(String id) {

        return mapper.findById(id);
    }



    public void edit(CheckItem item) {

        mapper.edit(item);

    }



    public List<CheckItem> findAll() {

        return mapper.findAll();
    }
}
